package com.eastseeway.radioproject.entities;

public enum FirmwareUpdateState {
    ALL_COMPLETED(0, "全部完成"),
    DOWNLOADING(1, "下载中"),
    UPDATING(2, "升级中"),
    COMPLETED(3, "已完成"),
    FAILED(4, "失败"),
    TIMEOUT(5, "超时"),
    IDLE(6, "");

    private final int code;
    private final String description;

    FirmwareUpdateState(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据状态码获取对应的枚举值
     */
    public static FirmwareUpdateState fromCode(int code) {
        for (FirmwareUpdateState state : values()) {
            if (state.getCode() == code) {
                return state;
            }
        }
        throw new IllegalArgumentException("Invalid state code: " + code);
    }

    @Override
    public String toString() {
        return "FirmwareUpdateState{" +
               "code=" + code +
               ", description='" + description + '\'' +
               '}';
    }
}
